﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using PPIDesktopClient.General;
using PPIProxy;
using System.Data;
using VMind.Global;
using PPIMobileInterface;

namespace PPIDesktopClient.Logic
{
    public class LVendor_Contacts
    {
        public static List<EVendor_Contact> SelectAllIdNameByVendor(int vendorID)
        {
            ConfigReader _Reader = ConfigReader.GetInstance();
            List<EVendor_Contact> _VendorContactList = new List<EVendor_Contact>();
            EVendor_Contact _VendorContact;
            DataSet ds = WVendor_Contacts.SelectAllIdNameByVendor(vendorID,_Reader.GetConnectionString());
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                _VendorContact = new EVendor_Contact();
                _VendorContact.Vendor_ContactId = ConvertHelper.ToInt32(dr["Vendor_ContactId"]);
                _VendorContact.Name = ConvertHelper.Tostring(dr["Name"]);
                _VendorContact.Vendor = new EVendor(ConvertHelper.ToInt32(dr["VendorFK"]));
                _VendorContactList.Add(_VendorContact);
            }
            return _VendorContactList;
        }

        public static List<EVendor_Contact> SelectAllIdName()
        {
            return SelectAllIdNameByVendor(0);
        }


        #region Mobile

        public static void InsertContacts(string connectionString)
        {
            List<EVendor_Contact> _contacts = SelectAllIdName();
            StringBuilder _query = new StringBuilder();
            foreach (EVendor_Contact c in _contacts)
            {
                _query.AppendLine("insert into tb_Users values (" + c.Vendor_ContactId + "," + c.Vendor.VendorId + ",'" + c.Name + "')");
            }
            Utils.InsertContacts(connectionString, _query.ToString());
        }

        #endregion
    }
}
